package k8s

import (
	"context"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/kubernetes"
	"log"
)

func GetNsList(k8sClient *kubernetes.Clientset) (nsRet []string) {
	nsItems, err := k8sClient.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{})
	if err != nil {
		log.Fatalln(err)
		return nil
	}
	for _, item := range nsItems.Items {
		nsRet = append(nsRet, item.Name)
	}
	return
}

func GetDeploymentList(k8sClient *kubernetes.Clientset, ns string) (depList []string) {
	deps, err := k8sClient.AppsV1().Deployments(ns).List(context.TODO(), metav1.ListOptions{})
	if err != nil {
		log.Fatal(err)
		return nil
	}
	for _, item := range deps.Items {
		depList = append(depList, item.Name)
	}
	return
}

func GetIngress(k8sClient *kubernetes.Clientset, ns string) (ingressList []string) {
	iList := k8sClient.NetworkingV1().Ingresses(ns)
	list, err := iList.List(context.Background(), metav1.ListOptions{})
	if err != nil {
		log.Fatal(err)
		return nil
	}
	for _, item := range list.Items {
		ingressList = append(ingressList, item.Name)
	}
	return
}
